/*******************************************************************************

This code file makes a BBL-to-tract crosswalk from PLUTO.

*******************************************************************************/

*** Manage settings

	set more off
	clear
	
	* Set globals
	global data "~/Dropbox (MIT)/Research/NYC421a/data"
	global pluto "~/Dropbox (MIT)/Research/NYC421a/data/raw/nyc_pluto_19v2_csv"

	* Set working directory
	cd "$pluto"
	
*** Import PLUTO data and merge into 421a dataset
	
	* Import PLUTO
	import delimited "$pluto/pluto_19v2.csv", encoding(ISO-8859-1)

*** Clean data
	
	* Clean borough variable
	drop borough
	rename borocode borough
	label define borough_label 1 "Manhattan" 2 "Bronx" 3 "Brooklyn" 4 "Queens" 5 "Staten Island"
	label values borough borough_label

	* Patch for missing Census tracts
	bys borough block: egen ct2010_ = mode(ct2010), minmode
	replace ct2010 = ct2010_ if missing(ct2010)
	drop ct2010_
	
	* Keep variables
	keep bbl borough block lot ct2010
	drop if missing(ct2010)

*** Save crosswalk
	
	save "$data/clean/xwalk_bbl_ct2010.dta", replace
	
